package com.api.syh56.shengyunhui.service.impl;

import com.api.syh56.shengyunhui.entity.DedicatedLinesC;
import com.api.syh56.shengyunhui.entity.common.ApiAreaDb;
import com.api.syh56.shengyunhui.mapper.ApiAreaDbMapper;
import com.api.syh56.shengyunhui.service.ApiAreaDbService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class ApiAreaDbServiceImpl extends ServiceImpl<ApiAreaDbMapper, ApiAreaDb> implements ApiAreaDbService {

    @Autowired
    private ApiAreaDbMapper apiAreaDbMapper;

    @Override
    public ArrayList<String> selectByCity(String[] codes) {
        ArrayList<String>  pcd = new ArrayList<>();
        for (String code :codes) {
            QueryWrapper<ApiAreaDb> wrapper = new QueryWrapper<>();
            wrapper.lambda().eq(ApiAreaDb::getAdCode,code);
            ApiAreaDb apiAreaDb = apiAreaDbMapper.selectOne(wrapper);
            pcd.add(apiAreaDb.getName());
        }
         return pcd;
    }

    @Override
    public ApiAreaDb selectByCity(String city) {
        QueryWrapper<ApiAreaDb> apiAreaDbQueryWrapper = new QueryWrapper<>();


        apiAreaDbQueryWrapper.lambda()
                .eq(ApiAreaDb::getName, city)
                .eq(ApiAreaDb::getLevel, "city");
        ApiAreaDb one = getOne(apiAreaDbQueryWrapper);
        return one;
    }

    @Override
    public ApiAreaDb selectByDistrict(String district) {

        QueryWrapper<ApiAreaDb> apiAreaDbQueryWrapper = new QueryWrapper<>();
        apiAreaDbQueryWrapper.lambda()
                .eq(ApiAreaDb::getName, district)
                .eq(ApiAreaDb::getLevel, "district");
        ApiAreaDb one = getOne(apiAreaDbQueryWrapper);
        return one;
    }

    @Override
    public ApiAreaDb selectByAdCode(String adCode) {
        QueryWrapper<ApiAreaDb> apiAreaDbQueryWrapper = new QueryWrapper<>();
        apiAreaDbQueryWrapper.lambda().eq(ApiAreaDb::getAdCode, adCode);
        ApiAreaDb one = getOne(apiAreaDbQueryWrapper);
        return one;
    }

    @Override
    public ApiAreaDb selectByCityN(String city) {
        QueryWrapper<ApiAreaDb> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .like(ApiAreaDb::getName,city);
        ApiAreaDb apiAreaDb = getOne(wrapper);
        return apiAreaDb;
    }
}
